from google.appengine.ext import bulkload
from google.appengine.api import datastore_types
from google.appengine.ext import search

"""
~/dev/google_appengine/tools/bulkload_client.py \
                     --filename wwwlim/events.csv \
                     --kind Event \
                     --url http://localhost:8081/load
                     --cookie='dev_appserver_login="admin:True"' 
"""
class EventLoader(bulkload.Loader):
    def __init__(self):
        bulkload.Loader.__init__(self, 'Event',
                         [('name', datastore_types.Text),
                          ('date', lambda d: datastore_types.datetime.datetime.strptime(d,'%Y-%m-%d %H:%M:%S')),
                          ('date_source', datastore_types.Text),
                          ('place', datastore_types.Text),
                          ('latitude', float),
                          ('longitude', float),
                          ('url', str),])

    def HandleEntity(self, entity):
        ent = search.SearchableEntity(entity)
        return ent

if __name__ == '__main__':
    bulkload.main(EventLoader())